package com.bdqn.demo.repository;

import com.bdqn.demo.pojo.SysUser;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface UserRepository extends JpaRepository<SysUser,Long> , JpaSpecificationExecutor<SysUser> {

    public SysUser findByUsrNameAndUsrPassword(String usrName,String usrPassword);

    @Query("select u from SysUser u where u.usrRoleId=?1")
    public Page<SysUser> findPageByUsrRoleId(Long roleId, Pageable pageable);

    @Transactional(timeout = 10)
    @Modifying
    @Query("update SysUser u set u.usrName=?1 where u.usrId=?2")
    public int modifyUsrNameByUsrId(String usrName,Long usrId);

    @Transactional(timeout = 10)
    @Modifying
    @Query("delete from SysUser u where u.usrId=?1")
    public int modifyByUsrId(Long usrId);


}
